import create_red from '../services/redpacket.js'
import rewardsj from '../services/rewardsj.js'
import Router from '../utils/router'
const fb  = {
  cardInfo: {
    user_info: null,
    titlefn(){
      let name = '';
      if (fb.user_info && fb.user_info.user_nickname){
      }else{
        fb.user_info = wx.getStorageSync('user_info');
      }
      if(name.length > 8){
        name = fb.user_info.user_nickname;
        name = name.substr(0, 8) + '...';
      }else{
        name = fb.user_info.user_nickname;
      }
      
      return `【${name}@你】先领红包再抢，真的超便宜！`;
    },
    path: '/pages/store/index',
    title: ``,
    imageUrl: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp/asset/redenvelopes/hb_share_01.jpg',
    customer_id: '',
    //分享地址 处理
    pathFn(that){
      let path = fb.cardInfo.path,
        user_info = wx.getStorageSync('user_info'),
        store_id = wx.getStorageSync('bslnid'),
        customer_id = (user_info && user_info.id) ? user_info.id : '';
      path += `?store_id=${store_id}&customer_id=${customer_id}&bybsid=${that.data.bybsid}`;
      return path;
    },
    goGonglue(){
      Router.go('web', `url=${encodeURIComponent('https://kpxd.zhengdianhaohuo.com/h5/#/active/win3_537')}`)
    }
  },
  //获取 红包数量
  getbonusNum(that, callback) {
    var share = that.data.share,
      time = 200;
    share.isShow = true;
    share.animate = false;
    var shareanimatefn = ()=>{
      that.setData({
        share: share
      });
      setTimeout(() => {
        share.animate = true;
        that.setData({
          share: share
        });
      }, time);
    }
    try{
      rewardsj.getBounty({}, res => { }, res => {
        if (res && res.statusCode == 200) {
          if (res.data && res.data.code == 1) {
            if (res.data.data.bonus_num && res.data.data.bonus_num > 0) {
              shareanimatefn();
            } else {
              return wx.showToast({
                title: '先下单才能发红包哦',
                icon: 'none',
                duration: 2500
              })
            }
          } else {
            shareanimatefn();
          }
        } else {
          shareanimatefn();
        }
      });
    } catch (e) {
      shareanimatefn();
    }
  },
  //获取 分享红包 id
  getSendRedEnvelope(that, callback) {
    let bybsid = '',
      share = that.data.share;
    create_red.getSendRedEnvelope({}, res => {
      if(res && res.code == 1){
        bybsid = res.data.bybsid;
      }
    }, res=>{
      that.setData({
        bybsid,
        ['share.bybsid']: bybsid
      });
      if (callback && (typeof callback) == 'function') {
        callback(res);
      }
    });
  },
	canvasWH : {
    w: 750,
    h: 1000,
	},
	shareJSON: [
		{
			bgImg:{//背景图
        //url: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp/asset/redenvelopes/fenxiangpyq2.jpg',
        url: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp/asset/redenvelopes/sharefriend.jpg',
        w: 750, h: 1000,x: 0,y: 0,
			},
			ewmImg:{//二维码位置
				w: 170,h: 170,x: 290,y: 590
			},
      txImgbg:{
        url: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp/asset/redenvelopes/avatar-bg.png',
        w: 80, h: 80, x: 138, y: 100
      },
			txImg:{//微信头像
        w: 80, h: 80,x: 138,y: 100
			},
			invite_me:{//me邀请你加入邻挑细选
        x: 245, y: 150, color: '#CE2930',textalgin: 'left',size: 28
			},
			invite_code:{//我的邀请码
        x: 379, y: 1006, color: '#454545', textalgin: 'left', size: 28
      },
      invite_code_txt: {//立刻扫码，早扫早赚钱
        x: 379, y: 1066, color: '#454545', textalgin: 'left', size: 28
      },
      invite_xy_txt1: {//听说红包领一送十，有这么美的事？
        x: 100, y: 558, color: '#293164', textalgin: 'canter', size: 28
      },
      invite_xy_txt2: {//听说红包领一送十，有这么美的事？
        x: 100, y: 608, color: '#293164', textalgin: 'canter', size: 28
      },
      invite_xy_txtfn(){
        let arr = [
          [''], //一人独享 不如将好运传递。', '红包领一变十，拿去不谢！
          [''],//听说这个红包领一送十，', '不敢独享，你也试试？
          [''],//我已验证！', '今日领用红包，果然一变十！
          [''],//数钱数到手抽筋，红包雨淋成土豪鸡！', '用一变十，你值得拥有！
          [''],//天呐，还有这种红包！', '你用一个得十个，好运气没完没了！
          [''],//咱俩都划算的小秘密：', '你用一个红包再得十个，我也能拿赏金！
        ],
        num = parseInt(Math.random()*6);
        return arr[num];
      },
		},
		// {
		// 	bgImg:{//背景图
		// 		url: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp_seller/asset/my/bg888.png',
		// 		w: 570,h: 890,x: 0,y: 0,
		// 	},
		// 	ewmImg:{//二维码位置
		// 		w: 150,h: 150,x: 92,y: 723
		// 	},
		// 	txImg:{//微信头像
		// 		w: 58,h: 58,x: 20,y: 15
		// 	},
		// 	invite_me:{//me邀请你加入邻挑细选
		// 		x: 87,y: 49,color: '#ffffff',textalgin: 'left',size: 22
		// 	},
		// 	invite_code:{//我的邀请码
		// 		x: 92+150+25,y: 770+14,color: '#c62d36',textalgin: 'left',size: 22
		// 	},
		// 	invite_code_txt:{//立刻扫码，早扫早赚钱
		// 		x: 92+150+25,y: 770+40+14,color: '#c62d36',textalgin: 'left',size: 22
		// 	}
		// },
		// {
		// 	bgImg:{//背景图
    //     url: 'https://kpxd.zhengdianhaohuo.com/kpxd_mp_seller/asset/my/bg999.png',
		// 		w: 570,h: 890,x: 0,y: 0,
		// 	},
		// 	ewmImg:{//二维码位置
		// 		w: 150,h: 150,x: 92,y: 723
		// 	},
		// 	txImg:{//微信头像
		// 		w: 58,h: 58,x: 20,y: 15
		// 	},
		// 	invite_me:{//me邀请你加入邻挑细选
		// 		x: 87,y: 49,color: '#ffffff',textalgin: 'left',size: 22
		// 	},
		// 	invite_code:{//我的邀请码
		// 		x: 92+150+25,y: 770+14,color: '#c62d36',textalgin: 'left',size: 22
		// 	},
		// 	invite_code_txt:{//立刻扫码，早扫早赚钱
		// 		x: 92+150+25,y: 770+40+14,color: '#c62d36',textalgin: 'left',size: 22
		// 	}
		// },
	]
}
module.exports = fb;